<?php
/**
 * Created by PhpStorm.
 * User: tengwei
 * Date: 2018/11/22
 * Time: 9:56 AM
 */

namespace common\sources\write\buypeppercash;

use Yii;
use common\models\craftsman\BuyPepperCash;

class BuyPepperCashAccess implements IBuyPepperCashAccess {
	public function modifyPepperCash($data) {
		$sql = 'UPDATE ' . BuyPepperCash::tableName() . ' SET reason = :reason,status = :status,update_time=:update_time WHERE id = :id ';
		return Yii::$app->db->createCommand($sql)
			->bindValues([
				':reason'      => $data['reason'],
				':status'      => $data['status'],
				':update_time' => time(),
				':id'          => $data['id']
			])->execute();
	}


	public function ModifyRemark($data) {
		$cash = BuyPepperCash::findOne(['id' => $data['id']]);
		if ($cash) {
			$cash->remark = $data['remark'];
			if ($cash->save()) {
				return true;
			}
		}
		return false;
	}

	public function AuditCash($data) {
		$cash = BuyPepperCash::findOne(['id' => $data['id']]);
		if ($cash) {
			$cash->status = $data['status'];
			if ($cash->save()) {
				return true;
			}
		}
		return false;
	}

	//提现审核操作
	public function newModifyPepperCash1($data) {
		$sql = 'UPDATE ' . BuyPepperCash::tableName() . ' SET reason = :reason,status = :status,update_time=:update_time ,auditor_time=:auditor_time ,auditor_user=:auditor_user WHERE id = :id ';
		return Yii::$app->db->createCommand($sql)
			->bindValues([
				':reason'       => $data['reason'],
				':status'       => $data['status'],
				':update_time'  => time(),
				':auditor_time' => time(),
				':auditor_user' => $data['operator'],
				':id'           => $data['id']
			])->execute();
	}

	//提现完成
	public function newModifyPepperCash($data) {
		$sql = 'UPDATE ' . BuyPepperCash::tableName() . ' SET reason = :reason,status = :status,update_time=:update_time ,end_time=:end_time ,end_user=:end_user ,kq_serial_number=:kq_serial_number WHERE id = :id ';
		return Yii::$app->db->createCommand($sql)
			->bindValues([
				':reason'           => $data['reason'],
				':status'           => $data['status'],
				':update_time'      => time(),
				':end_time'         => time(),
				':end_user'         => $data['operator'],
				':kq_serial_number' => $data['kq_serial_number'],
				':id'               => $data['id']
			])->execute();
	}

}